package com.ryskoo.catering.coupon.repository;

import com.ryskoo.catering.coupon.domain.CouponPO;
import com.ryskoo.common.hclconstant.CouponTypeEnum;
import com.ryskoo.framework.core.bean.QueryConditionEnum;
import com.ryskoo.framework.core.bean.QueryMessageDTO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import com.ryskoo.framework.core.utils.DateFormatHelper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CouponJPAImpl extends BasicJPAImpl<CouponPO> implements ICouponRepository {
    @Override
    public List<CouponPO> getListForVendorByVendorUuid(String vendorUuid) {
        String nowTime = DateFormatHelper.getNowTimeStr();
        QueryMessageDTO qm = new QueryMessageDTO();
        qm.addCondition("vendorUuid", QueryConditionEnum.EQ.name(), vendorUuid);
        qm.addCondition("couponType", QueryConditionEnum.EQ.name(), CouponTypeEnum.VENDOR.getValue());
        qm.addCondition("state", QueryConditionEnum.EQ.name(), true);
        qm.addCondition("startValidTime", QueryConditionEnum.LT.name(), nowTime);
        qm.addCondition("endValidTime", QueryConditionEnum.GE.name(), nowTime);
        return this.queryByCondition(qm, false);
    }
}
